import { formatBigNumber, formatTimestamp } from "@/comm/format";
import i18n from "@/locals";

export const getBaseOption = (ary: any[]) => {
    // let max = Math.max(...ary.map(i => Math.abs(i.fundingRate * 100)));
    const max = Math.max(...ary.map(item=>item.fundingRate)) * 100;
    const min = Math.min(...ary.map(item=>item.fundingRate)) * 100;
    // let min = Math.min(...ary.map(i=>Math.abs(i.fundingRate*100)));
    // console.log("------max----min", max, min);
    let option: any = {
        xAxis: {
            type: "category",
            boundaryGap: false,
            axisLabel: {
                data: ary.map((val, i) => {
                    return val["fundingTime"];
                }),
                formatter: function (value: any) {
                    return formatTimestamp(ary[value]["fundingTime"]);
                }
            }
        },
        yAxis: {
            type: "value",
            splitLine: {
                show: false
            },
            max: max,
            min: min,
            axisLabel: {
                formatter: (a: any) => {
                    // return formatBigNumber(a, 2);
                    return a + "%";
                }
            }
        },
        legend: {
            data: [i18n.global.t("message.Position.table.f.a")],
            bottom: 10,
            textStyle: {
                fontSize: 12,
                color: "#ffffff"
            }
        },
        tooltip: {
            trigger: "axis",
            axisPointer: {
                type: "cross",
                label: {
                    color: "#ffffff",
                    backgroundColor: "#000000",
                    formatter: function (a: any) {
                        if (a.axisDimension == "y") {
                            let num = Number(a.value);
                            // if (num < 1) {
                            //     return num.toFixed(6);
                            // }
                            return num + "%";
                        }
                        return formatTimestamp(ary[a.value]["fundingTime"]); // 这里使用默认的日期格式
                    }
                }
            },
            borderWidth: 0,
            backgroundColor: "#2F363E",
            formatter: function (params: any[]) {
                // console.log(params, "----");
                let t1 = `<span class='ct-num'>${formatTimestamp(params[0].axisValueLabel)}</span>`;
                let s = [`<span class='ct-tip'>${i18n.global.t("message.Position.table.f.a")} </span> <span class='ct-num'>${params[0].value}%</span>`];

                return [t1, ...s].join("<br>");
            }
        },
        series: [
            {
                name: i18n.global.t("message.Position.table.f.a"),
                stack: "Total",
                data: ary.map((val, i) => Number(val.fundingRate) * 100),
                type: "line",
                emphasis: { disabled: true },
                itemStyle: {
                    color: "#2DAEA1"
                },
                lineStyle: {
                    width: 0.1,
                    normal: {
                        color: "#2DAEA1", //改变折线点的颜色
                        lineStyle: {
                            // color: '#fff' //改变折线颜色
                        }
                    }
                }
            }
        ]
    };

    return option;
};
